package com.xxx.server.controller;


import com.xxx.server.pojo.Role;
import com.xxx.server.pojo.response.RespBean;
import com.xxx.server.service.IRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  权限组 角色管理
 * </p>
 *
 * @author cd
 * @since 2023-12-19
 */
@RestController
@RequestMapping("/system/basic/permission")
public class RoleController {

    @Autowired
    private IRoleService iRoleService;

    @PostMapping
    public RespBean addRole(@RequestBody Role role){
        Boolean aBoolean = iRoleService.getMenusWithRole(role);
        if (aBoolean){
            return RespBean.success("ok", true);
        }
        return RespBean.error("保存失败");
    }
    @GetMapping
    public List<Role> getRoleList(){
        List<Role> roleList = iRoleService.getRoleList();
        return roleList;
    }
    @DeleteMapping("role/{id}")
    public RespBean deleteRole(@PathVariable int id){
        boolean b = iRoleService.removeById(id);
        if (b) {
            return RespBean.success("删除成功");
        }
        return RespBean.error("删除失败");
    }



}
